package com.ruoyi.web.controller.project;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.ProjectEnvironmentParams;
import com.ruoyi.project.service.IProjectEnvironmentParamsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目环境参数Controller
 *
 * @author yhg
 * @date 2022-10-19
 */
@RestController
@RequestMapping("/project/params")
public class ProjectEnvironmentParamsController extends BaseController
{
    @Autowired
    private IProjectEnvironmentParamsService projectEnvironmentParamsService;

    /**
     * 查询项目环境参数列表
     */
    @PreAuthorize("@ss.hasPermi('project:params:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectEnvironmentParams projectEnvironmentParams)
    {
        startPage();
        List<ProjectEnvironmentParams> list = projectEnvironmentParamsService.selectProjectEnvironmentParamsList(projectEnvironmentParams);
        return getDataTable(list);
    }

    /**
     * 导出项目环境参数列表
     */
    @PreAuthorize("@ss.hasPermi('project:params:export')")
    @Log(title = "项目环境参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectEnvironmentParams projectEnvironmentParams)
    {
        List<ProjectEnvironmentParams> list = projectEnvironmentParamsService.selectProjectEnvironmentParamsList(projectEnvironmentParams);
        ExcelUtil<ProjectEnvironmentParams> util = new ExcelUtil<ProjectEnvironmentParams>(ProjectEnvironmentParams.class);
        util.exportExcel(response, list, "项目环境参数数据");
    }

    /**
     * 获取项目环境参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:params:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(projectEnvironmentParamsService.selectProjectEnvironmentParamsById(id));
    }

    /**
     * 新增项目环境参数
     */
    @PreAuthorize("@ss.hasPermi('project:params:add')")
    @Log(title = "项目环境参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectEnvironmentParams projectEnvironmentParams)
    {
        return toAjax(projectEnvironmentParamsService.insertProjectEnvironmentParams(projectEnvironmentParams));
    }

    /**
     * 修改项目环境参数
     */
    @PreAuthorize("@ss.hasPermi('project:params:edit')")
    @Log(title = "项目环境参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectEnvironmentParams projectEnvironmentParams)
    {
        return toAjax(projectEnvironmentParamsService.updateProjectEnvironmentParams(projectEnvironmentParams));
    }

    /**
     * 删除项目环境参数
     */
    @PreAuthorize("@ss.hasPermi('project:params:remove')")
    @Log(title = "项目环境参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectEnvironmentParamsService.deleteProjectEnvironmentParamsByIds(ids));
    }
}
